﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SBPweb.RIA.Server.Common.Hosting
{

    public class SiteBinding
    {

        public SiteBinding(string protocol, string ip, string hostName, int port)
        {
            Protocol = protocol;
            IP = ip;
            HostName = hostName;
            Port = port;
        }

        public SiteBinding(string protocol, string ip, string hostName, string port)
            : this(protocol, ip, hostName, Convert.ToInt16(port))
        {
        }

        public string Protocol
        {
            get;
            set;
        }

        public string IP
        {
            get;
            set;
        }

        public string HostName
        {
            get;
            set;
        }

        public int Port
        {
            get;
            set;
        }

        public override string ToString()
        {
            return string.Format("{0}://{1}:{2}", Protocol,
                string.IsNullOrEmpty(HostName) ?
                    IP != "*" ? IP : "localhost"
                    : HostName,
            Port);
        }

        public Uri ToUri()
        {
            return new Uri(this.ToString(), UriKind.Absolute);
        }

    }

}